<?php include "include/function_library.php"; ?>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php include "html/header.html"; ?>

</head>
<body class="tcuk home">

	<div id="wp">
	
		<?php  include "html/menu.html"; ?>
		
		<!-- CONTENT STARTS-->
		<div id="ct"> 	
			
			<?php 
			if(post("hotel_submit")) {
				$hotel_name 		= post("hotel_name");
				$hotel_tel 			= post("hotel_phone");
				$hotel_capacity 	= post("hotel_capacity");
				$hotel_type 		= post("hotel_type");
				$hotel_price 		= post("hotel_price");
				$hotel_description	= post("hotel_description");
				$hotel_id			= post("id");
				
				$hotel_address = "2";
				
				$query = "update hotel set name='$hotel_name', tel='$hotel_tel', capacity='$hotel_capacity', type='$hotel_type', price='$hotel_price', 
															description='$hotel_description' where id = $hotel_id";
				
				$link = connect();
				$result = mysql_query($query, $link) or die("Sql Error! " . mysql_error());
				
				mysql_close($link);
				
				if($result) {
					redirect("hotel_detail.php?edited=1&id=$hotel_id");
				} else {
					echo "<div class='alert error'>Error! Could Not Update! There is(are) error(s) in the form!</div>";
				}

			} 
			
			$id = get("id");
			$query = "SELECT h.id, name, tel, capacity, type, price, description FROM hotel h WHERE h.id=$id";
				
			$result = sql_query($query);
			$tuple = mysql_fetch_assoc($result);
			?>
			<form action="<?php echo curPageURL(); ?>?id=<?php echo $id ?>" method="post">
			<ul id="signup_form" style="width: 50%; margin-left: auto; margin-right: auto; margin-top: 30px; list-style: none;">
				<li style="border: none;">
					<label>Name </label>
					<input type="text" id="hotel_name" name="hotel_name" value="<?php echo $tuple["name"]; ?>" placeholder="Hotel name.." style="width: 250px;"/>
				</li>
				<li>
					<label>Phone </label>
					<input type="text" id="hotel_phone" name="hotel_phone" value="<?php echo $tuple["tel"]; ?>" placeholder="Hotel phone.." style="width: 250px;"/>
				</li>
				<li>
					<label>Capacity </label>
					<input type="number"  id="hotel_capacity" name="hotel_capacity" value="<?php echo $tuple["capacity"]; ?>" placeholder="Capacity.." style="width: 250px;"/>
				</li>
				<li>
					<label>Type </label>
					<select id="hotel_type" name="hotel_type">
						<option value="Small hotel" selected="<?php $tuple["type"] == 'Small hotel' ?>">Small hotel</option>
						<option value="Medium sized hotel" selected="<?php $tuple["type"] == 'Medium sized hotel' ?>">Medium sized hotel</option>
						<option value="Large hotel" selected="<?php $tuple["type"] == 'Large hotel' ?>">Large hotel</option>
						<option value="Mega hotel" selected="<?php $tuple["type"] == 'Mega hotel' ?>">Mega hotel</option>
						<option value="Chain hotel" selected="<?php $tuple["type"] == 'Chain hotel' ?>">Chain hotel</option>
					</select>
				</li>
				<li>
					<label>Price</label>
					<input type="number" id="hotel_price" name="hotel_price" value="<?php echo $tuple["price"]; ?>" placeholder="Price.." style="width: 120px;"/>
				</li>
				<li>
					<label>Description </label>
					<textarea rows="10" id="hotel_description" name="hotel_description" placeholder="Description.." style="width: 250px;"><?php echo $tuple["description"]; ?></textarea>
				</li>
				<li>
					<input type="hidden" name="id" value="<?php echo $id ?>"/>
					<input type="submit" id="hotel_submit" name="hotel_submit" value="Save" style="width: 90px; height:30px; margin-left: 80px;"/>
				</li>
			</ul>
			</form>
		
		</div> 	
		<!-- CONTENT ENDS-->		
		
		<?php include "html/footer.html"; ?>
		
	</div>
	
</body>
</html>